#include <bits/stdc++.h>
#define rp(i, l, r) for(int i = l; i <= r; i++)
using namespace std;

int readint() {
	int x = 0, f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar();}
	while(ch >='0' && ch <= '9') { x = x * 10 + (ch - '0'); ch = getchar();}
	return f * x;
}
const int MAXN = 105;
int T, n, a[MAXN];
namespace subtask1 {
int maxv;
bool col[MAXN]; // 0 blue 1 red
void dfs(int now, int lstB, int lstR, int res) {
	if(now == 1) {
		dfs(now + 1, 1, 0, 0);
		dfs(now + 1, 0, 1, 0);
	}
	else{
		if(now == n + 1) {
			maxv = max(maxv, res);
			return;
		}
		int valB = 0, valR = 0;
		if(lstB > 0 && a[lstB] == a[now]) valB = a[lstB];
		if(lstR > 0 && a[lstR] == a[now]) valR = a[lstR];
		dfs(now + 1, now, lstR, res + valB);
		dfs(now + 1, lstB, now, res + valR);
	}
}
void solve() {
	maxv = 0;
	dfs(1, 0, 0, 0);
	printf("%d\n", maxv);
}
}
namespace subtask2 {
const int MAXM = 105;
int dp[MAXM][MAXM][MAXM];
void solve() {
	
}
}
int main() {
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	T = readint();
	while(T--) {
		n = readint();
		rp(i, 1, n) {
			a[i] = readint();
		}
		if(n <= 15) {
			subtask1::solve();
		}
		
	}
	return 0;
}
